// forEach就是给数组所有的参数执行一遍函数
const forEach = (arr, fn) => {
  for (let val of arr) {
    fn(val)
  }
}
let arr = [1, 2, 3, 4, 5, 6, 7]
forEach(arr, (arr) => console.log(arr))

// 模拟filter
// 返回满足条件的数组选项
const filter = (arr, fn) => {
  let results = []
  for (let val of arr) {
    if (fn(val)) {
      results.push(val)
    }
  }
  return results
}
console.log(filter(arr, (arr) => arr > 4))
